package part3;

import java.util.*;

public class Poke {
    public static void main(String[] args) {
        //准备牌
        //添加牌索引
        List<Integer> index = new ArrayList<>();
        //Collections.addAll(index,1,2,3);
        for (int i = 0; i < 54; i++) {
            index.add(i);
        }
        //System.out.println(index);

        //定义数组存储花色和13张牌,添加到一个List集合
        List<String> array = new ArrayList<>();
        array.add("大王");
        array.add("小王");
        String[] colors = {"♠", "♥", "♣", "♦"};
        String[] nums = {"2","A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        for (String num : nums){
            for (String color : colors){
                array.add(color + num);
            }
        }
        //  System.out.println(array);

        //存到Map集合
        Map<Integer, String> poker = new HashMap<>();
        int i = 0;
        for (Integer integer : index) {
            poker.put(integer, array.get(i));
            i++;
        }
        //System.out.println(poker);


        //洗牌
        Collections.shuffle(index);
        //System.out.println(index);


        //发牌
        List<Integer> player0 = new ArrayList<>();
        List<Integer> player1 = new ArrayList<>();
        List<Integer> player2 = new ArrayList<>();
        List<Integer> dipai = new ArrayList<>();

        for (int j = 0; j < index.size(); j++) {
            Integer _index = index.get(j);  //获取牌
            if (j >= 51) {
                dipai.add(_index);
            } else if (j % 3 == 0) {
                player0.add(_index);
            } else if (j % 3 == 1) {
                player1.add(_index);
            } else {
                player2.add(_index);
            }
        }


        //给每个人的手牌排序
        Collections.sort(player0);
        Collections.sort(player1);
        Collections.sort(player2);
        Collections.sort(dipai);


        // 看牌,调用看牌方法
        String[] names = {"玩家0","玩家1","玩家2","底牌"};
        lookPoker(poker,player0,names[0]);
        lookPoker(poker,player1,names[1]);
        lookPoker(poker,player2,names[2]);
        lookPoker(poker,dipai,names[3]);


    }


    // 看牌,根据玩家手牌索引获取牌值
    public static void lookPoker(Map<Integer, String> poker,
                                 List<Integer> list, String name) {
        System.out.print("\r\n" + name + ":");
        for (Integer integer : list) {
            System.out.print(" [" + poker.get(integer)+"]");
        }
    }

}
